using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using Chaotic.Core.Extension;

namespace Chaotic.Module.DBTool.Converters;

[ValueConversion(typeof(string), typeof(BitmapImage))]
public class ImageConverter : IValueConverter
{
	public object? Convert(object? value, Type targetType, object parameter, CultureInfo culture)
	{
		if (value == null)
		{
			return null;
		}
		string text = value.ToString();
		if (string.IsNullOrEmpty(text))
		{
			return null;
		}
		return ImageSourceExtension.GetImageSource("Chaotic.Module.DBTool", text);
	}

	public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
	{
		throw new NotImplementedException();
	}
}
